package com.goodving.guli.activity;

import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.bt.profile.scale.GuliLog;
import com.goodving.guli.bt.profile.scale.XMBLEManager;
import com.goodving.guli.fragment.BindDevicesBandFragment;
import com.goodving.guli.fragment.SettingWeightFragment;
import com.goodving.guli.fragment.SettingFragment;
import com.goodving.guli.model.DeviceSource;
import com.goodving.guli.view.GuliHardwareDevice;
import com.goodving.guli.view.ScaleBindFragment;

/**
 * Created by john on 2015/11/24.
 */
public class SettingContainerActivity extends SystemBarTintActivity {
    public static final String f9257a = "device_type";
    private static final String TAG = "SettingContainerActivity";

    public void m14076a() {
    }

    public void m14077b() {
        finish();
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        SettingFragment efVar = (SettingFragment) getFragmentManager().findFragmentByTag(SettingFragment.class.getName());
        GuliLog.tracePrintInfo(TAG, "setting fragment =" + efVar);
        if (efVar != null) {
            efVar.onActivityResult(i, i2, intent);
        }
    }

    protected void onCreate(Bundle bundle) {
        Fragment fragment;
        String str;
        int color;
        CharSequence charSequence;
        super.onCreate(bundle);
        setContentView((int) R.layout.activity_settings_container);
        Resources resources = getResources();
        int intExtra = getIntent().getIntExtra(f9257a, -1);
        String string;
        Fragment efVar;
        Object obj;
        if (intExtra == GuliHardwareDevice.RING.ordinal()) {
            string = resources.getString(R.string.guli_band);
            if (DeviceSource.hasBindBracelet()) {
                efVar = new SettingFragment();
                String name = SettingFragment.class.getName();
                if (XMBLEManager.m25158c()) {
                    fragment = efVar;
                    str = name;
                    color = resources.getColor(R.color.bg_mode_step);
                    charSequence = string;
                } else {
                    fragment = efVar;
                    str = name;
                    color = resources.getColor(R.color.bg_color_grey);
                    charSequence = string;
                }
            } else {
                efVar = new BindDevicesBandFragment();
                fragment = efVar;
                str = BindDevicesBandFragment.class.getName();
                color = resources.getColor(R.color.bg_color_grey);
                charSequence = string;
            }
        }
        else if (intExtra == GuliHardwareDevice.SCALE.ordinal()) {
            string = resources.getString(R.string.scale);
            if (DeviceSource.hasBindWeight()) {
                efVar = new SettingWeightFragment();
                fragment = efVar;
                str = SettingWeightFragment.class.getName();
                color = resources.getColor(R.color.bg_mode_weight);
                charSequence = string;
            } else {
                efVar = new ScaleBindFragment();
                fragment = efVar;
                str = ScaleBindFragment.class.getName();
                color = resources.getColor(R.color.bg_color_grey);
                charSequence = string;

            }
        } else {
            finish();
            return;
        }
        ((TextView) findViewById(R.id.title)).setText(charSequence);
        findViewById(R.id.root_layout).setBackgroundColor(color);
        FragmentTransaction beginTransaction = getFragmentManager().beginTransaction();
        beginTransaction.add(R.id.fragment_container, fragment, str);
        beginTransaction.commit();
    }
}
